package day18.zhiyou100;

// 定义测试类
class Test2 {
    public static void main(String[] args) throws InterruptedException {
        // 构建实现类的对象
        MyRunnable runnable = new MyRunnable();
        // 创建Thread类对象
        Thread t1 = new Thread(runnable);
        Thread t2 = new Thread(runnable);
        Thread t3 = new Thread(runnable);
        // 调用start()方法
        t1.start();
        t2.start();
        t3.start();

        t1.join();// 等待
        // 打印50个数字
        for (int i = 0; i < 50; i++) {
            System.out.println(Thread.currentThread().getName()+"---" + i);
        }
        //Object
    }
}


public class MyRunnable implements Runnable{

    @Override
    public void run() {
        for (int i = 0; i < 50; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "---" + i);
        }
    }

}
